package com.mingqi.enetconnected.net.request;

import android.content.Context;

import com.google.gson.reflect.TypeToken;
import com.mingqi.enetconnected.data.bean.AdInfo;

import java.io.File;
import java.lang.reflect.Type;
import java.util.List;

/**
 * 232 CMS
 * 23201 AdRemoteService
 * 共1个，完成
 */
public class AdRemoteRequest {
    /**
     * 广告信息
     */
    public final static String AD_REMOTE_URL = "/v1/cms/service/ad?adBannerType=app&adBanner=home";

    /**
     * @param cxt
     * @return
     * @throws Exception
     */
    public static List<AdInfo> getAdInfo(Context cxt) throws Exception {
        Type type = new TypeToken<List<AdInfo>>() {
        }.getType();
        Communicator<List<AdInfo>> communicator = new Communicator<>(cxt, AD_REMOTE_URL);
        return communicator.get(type);
    }

    /**
     * @param cxt
     * @param url
     * @param name 文件名
     * @return
     * @throws Exception
     */
    public static boolean downloadAdImage(Context cxt, String url, String name) throws Exception {
        File file = Communicator.downloadFile(cxt, url, name);
        if (file.exists()) {
            return true;
        }
        return false;
    }
}
